package BNS.plumbing;

import java.util.Enumeration;

import BNS.graphs.Node;

/** This class handles the assignment of nodes to clients.	*/
public abstract class Manager implements Runnable {
	
	protected BNSGameController game;
	protected Timing clock;
	protected int timeLimit;

	/** starts the thread that reads the event file and drives the simulated game events */
	public void begin() { 
//		System.err.println("Manager.begin() ");	Thread.dumpStack();
		new Thread(this).start(); }
		
	/** Called to give the Manager a chance to determine if there are enough clients
		available to play the current game, and to initialize the mechanism that will
		assign clients to graph nodes. (It searches for all clients that are currently
		running a waitgame and makes a list of them.)
		This is publicly exposed so that it can be overridden if a different policy is desired.
		@return a flag indicating there are sufficient players available.
		*/
//	public boolean ready(int required);
	
	/** Assigns a client to the given node at random from amongst the ones on the list 
		of clients discovered during the call to ready() to be available for play.
		This is publicly exposed so that it can be overridden if a different policy is desired.
		*/
//	public ClientLiaison assign(Node node) {
//		return list.remove(rand.nextInt(list.size()));
//		}
	
	/** Assigns every node to a different client.
		@param gameController the BNSGame that will be played.
		@param nodes an Enumeration of all Nodes that need to be given a client.
		*/
	public abstract boolean assignClients(BNSGameController gameController, Enumeration<Node> nodes);
	
	/** Shuts down a game by reclaiming all its clients and directing them to waitgame instead.
		Also, this method records the payoff of each player in sessionLog. */
	public abstract void closeGame();
	
	/** puts a short message in the status field of each client, 
		which will be sent to the client on the next call to passUpdate().
		The Client Persona might be built to display this in a message bar.
		The current implementation assumes there is only one active game. */
	public abstract void bulletin(String message);
	
	}
